package com.litchi.tutor.common.util;


/**
 * @author XuRuiPeng
 * @date 2021/11/15 15:00
 */
public class HideSensitiveUtil {

    private static Integer RESULT_NAME_LENGTH  = 2;

    public static String protectedMobile(String mobile) {
        String phoneNumber = mobile.substring(0, 3) + "****" + mobile.substring(7, mobile.length());
        return phoneNumber;
    }


    public static String protectedWxid(String wxid) {
        return wxid.replaceAll(wxid, "******");
    }

    public static String protectedName(String userName){
        userName = userName.trim();
        char[] r = userName.toCharArray();
        String resultName = "";
        if(r.length == RESULT_NAME_LENGTH){
            resultName =  r[0]+"*";
        }
        if (r.length > RESULT_NAME_LENGTH) {
            String star = "";
            for (int i = 0; i < r.length-RESULT_NAME_LENGTH; i++) {
                star=star+"*";
            }
            resultName = r[0]+star+r[r.length-1];
        }
        return resultName;
    }

}
